package com.unione.map.view.fragment

import android.os.Bundle
import android.view.View
import android.view.View.OnClickListener
import androidx.navigation.Navigation
import androidx.viewbinding.ViewBinding
import com.unione.map.R
import com.unione.map.view.act.MainActivity
import com.unione.unione_base.view.BaseFragment
import com.unione.unione_base.view.BaseViewModel

abstract class AppBaseFragment<VB : ViewBinding> : BaseFragment<VB>(), OnClickListener {


    override fun init() {
        getViewModel()?.apply {
            exception.observe(viewLifecycleOwner) {

            }
        }
    }


    fun onBackHome() {
        val nvController =
            Navigation.findNavController(
                requireActivity() as MainActivity,
                R.id.fragment_container_view
            )
        nvController.navigate(R.id.mainFragment)
    }

    fun onBackLastPage() {
        val nvController =
            Navigation.findNavController(
                requireActivity() as MainActivity,
                R.id.fragment_container_view
            )
        nvController.popBackStack()
    }

    fun onExitApp() {

    }

    fun onVoiceBtnClicked() {

    }

    override fun onClick(v: View?) {
        if (v == null) return
        when (v.id) {
            R.id.clVoice -> {
                onVoiceBtnClicked()
            }

            R.id.clHome -> {
                onBackHome()
            }
            R.id.btnBack,
            R.id.clBack -> {
                onBackLastPage()
            }
        }
    }

    open fun getViewModel(): BaseViewModel? {
        return null
    }

}